package com.pacifictextiles.qc.inspection.server.model.test;
import java.util.LinkedList;
import java.util.List;
import com.pacifictextiles.qc.inspection.server.model.dao.impl.WasteDAOImpl;
import com.pacifictextiles.qc.inspection.server.model.vo.Waste;

public class testAddWaste {
	public static void main(String[] args) {
		
		//new an interface
		 
		
		WasteDAOImpl testWasteDAOImpl = new WasteDAOImpl();

		//set instance variable of waste
		
		
		Waste waste = new Waste();
		waste.setIndexInRoll(5);
		waste.setRollNo("21");
		waste.setBeginPosition(0);
		waste.setEndPosition(0);
		waste.setWasteLength(0);
		waste.setDefectCode(0);

		//add OK 
		 
		
		try {
			testWasteDAOImpl.addWaste(waste);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("add waste failed");
		}

		//delete OK 
		 
		
		try {
			testWasteDAOImpl.deleteWaste("21", 5);
		} catch (Exception e) {
			//e.printStackTrace();
			System.out.print("执行删除失败失败"+"\n");
		}

		// get list 
		 
		
		try {
			List<Waste> wasteList = new LinkedList<Waste>();
			wasteList = testWasteDAOImpl.getWasteList("21");
			printWasteList(wasteList);

			// 判断有无查询到结果
			if (wasteList.isEmpty()) {
				System.out.print("没有查询到 waste的信息" + "\n");
			}
		} catch (Exception e) {
			// e.printStackTrace();
			System.out.print("获取List失败" + "\n");
		}
	}

	private static void printWasteList(List<Waste> wasteList) throws Exception {
		int counterMinus = wasteList.size() - 1;
		while (counterMinus >= 0) {
			Waste waste_receive = wasteList.get(counterMinus);
			System.out.print(waste_receive.getIndexInRoll() + "\n"
					+ waste_receive.getRollNo() + "\n"
					+ waste_receive.getBeginPosition() + "\n"
					+ waste_receive.getEndPosition() + "\n"
					+ waste_receive.getDefectCode() + "\n"
					+ waste_receive.getDateAndTime() + "\n\n\n");
			counterMinus--;
		}
	}

}// public class
